import Vue from "vue";
Vue.directive(
  "hasCC",
  /*注册一个全局自定义指令 v-focus */ {
    // 当绑定元素插入到 DOM 中。
    inserted: function(el, binding) {
      let menus = JSON.parse(localStorage.getItem("menus"));
      let power = menus.action;
      let flag1 = power.find(
        (ee) =>
          ee.flag === binding.value[0].flag && ee.marking === binding.value[0].name
      );
      let flag2 = power.find(
        (ee) =>
          ee.flag === binding.value[1].flag && ee.marking === binding.value[1].name
      );
      if (!flag1 || !flag2) el.style.display = "none";
      // let value = binding.value;
    },
  }
);
Vue.directive(
  "has",
  /*注册一个全局自定义指令 v-focus */ {
    // 当绑定元素插入到 DOM 中。
    inserted: function(el, binding) {
      if (binding.value) {
        let menus = JSON.parse(localStorage.getItem("menus"));
        let power = menus.action;
        if (typeof binding.value == "string") {
          let flag = power.find((ee) => ee.flag === binding.value);
          if (!flag) el.style.display = "none";
        } else {
          let flag = power.find(
            (ee) =>
              ee.flag === binding.value.flag && ee.name === binding.value.name
          );
          if (!flag) el.style.display = "none";
        }
      }
    },
  }
);
Vue.directive(
  "hasC",
  /*注册一个全局自定义指令 v-focus */ {
    // 当绑定元素插入到 DOM 中。
    inserted: function(el, binding) {
      if (binding.value) {
        let menus = JSON.parse(localStorage.getItem("menus"));
        let power = menus.action;
        if (typeof binding.value == "string") {
          let flag = power.find((ee) => ee.flag === binding.value);
          if (!flag) el.style.display = "none";
        } else {
          let flag = power.find(
            (ee) =>
              ee.flag === binding.value.flag &&
              ee.marking === binding.value.name
          );
          if (!flag) el.style.display = "none";
        }
      }
    },
  }
);
Vue.directive(
  "dis",
  /*注册一个全局自定义指令 v-focus */ {
    // 当绑定元素插入到 DOM 中。
    inserted: function(el, binding) {
      if (binding.value) {
        let menus = JSON.parse(localStorage.getItem("menus"));
        let power = menus.action;
        let flag = power.find((ee) => ee === binding.value);
        if (!flag) el.setAttribute("disabled", "disabled");
      }
    },
  }
);
